/**
 * 
 */
package com.airnewslinkosky.ticket.ui.order;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

import com.airnewslinkosky.ticket.FlyApplication;
import com.airnewslinkosky.ticket.R;
import com.airnewslinkosky.ticket.model.ChangeDateData;
import com.airnewslinkosky.ticket.model.FlightInfo;
import com.airnewslinkosky.ticket.model.FlightOrder;
import com.airnewslinkosky.ticket.model.FlightRestrict;
import com.airnewslinkosky.ticket.model.OrderInfo;
import com.airnewslinkosky.ticket.model.OrderInfoResult;
import com.airnewslinkosky.ticket.model.SearchOrder;
import com.airnewslinkosky.ticket.model.TotalOrderInfoResult;
import com.airnewslinkosky.ticket.net.WebAccessor;
import com.airnewslinkosky.ticket.pay.util.BaseHelper;
import com.airnewslinkosky.ticket.ui.BaseActivity;
import com.airnewslinkosky.ticket.ui.flight.CreditCard;
import com.airnewslinkosky.ticket.util.AddrUtil;
import com.airnewslinkosky.ticket.util.DateUtil;
import com.airnewslinkosky.ticket.util.FlyUtil;
import com.mobclick.android.MobclickAgent;

/**
 * @author luoxz
 *
 */
public class OrderDetail extends BaseActivity implements OnClickListener {
	
	public final int SEARCH_ERROR=7;
	public final static int SUCCESS = 0;
	public final static int FAIL = 1;
	public final static int CANCEL_SUCCESS = 2;
	public final static int ABOLISH_SUCCESS = 3;
	public final static int RETURN_AMOUNT_SUCCESS = 4;
	public final static int APPLY_FOR_REFUND_SUCCESS = 5;
	public final static int MODIFY_NO_SUCCESS = 6;
	public final static int CHANGEDATE_SUCCESS = 7;
	
	public  final int DATE_DIALOG_ID = 11;
	public  final int TIME_DIALOG_ID = 12;
	public  final int REFUNDTYPE_DIALOG_LIST = 10;
	
	public static OrderInfo ORDER_INFO;
	public static FlightOrder ORDER_DETAIL;
	//退改签政策
	private RelativeLayout flightDetailRestrict,ticketOrderNo_layout;
	private boolean isOpenRestrict = true;
	private TextView restrict;
	private ImageView restrictArrow;
	private String restrictValue;
	private FlightRestrict flightRestrict;
	private FlightInfo flight;
	
	
	
	private ProgressDialog progressDialog = null;
	
	TextView departureDate, departureWeek, flightNo,
		order_status, order_no, order_date,totalAmount,
		ticketOrderNo,passengerName,course,
		ticketOrder_date,tripType,rebate,ticket_status,
		
		fromCity, flight_depart, fromtime, fromaf, 
		toCity, flight_arrive, totime, toaf, 
		airc, baseCabin, food, stopNo, flight_price_title2, cabinPrice, discount, price, basePrice, fuelTax,
		airc0, others, airc1, airc2,
		
		consigneeName,consigneePhone,consigneeAddress,itineraryNo,
		passenger_name, passenger_id_number,
		contactor_name, contactor_mobile,
		sumPrice,
		
		insurancePrice,postFee,invoiceFee;
	
	private LinearLayout itinerary_info_sum_layout;
	private AddrUtil addrUtil;
	
	private FlyUtil flyUtil;
	
	//后退回列表页时使用
	public static List<OrderInfo> orderist = new ArrayList<OrderInfo> ();
	
	private Toast toast;
	
	//申请原因
	private AlertDialog refundmemtDialog;
	private EditText refundmemt_comment;
	private FrameLayout fl;
	
	//修改乘客证件号码
	private AlertDialog modifyPassengerIDNoDialog;
	private EditText new_PassengerIDNo;
	
	//机票申请改期
	private AlertDialog changeDateApplyDialog;
	private EditText newAirFlightNo,applyReason;
	private LinearLayout new_date_layout;
	private int mYear;
    private int mMonth;
    private int mDay;
    private int mHour = 0;
    private int mMinute = 0;
    private String newDateStr;
    private TextView newDate;

    //申请退订
    private LinearLayout refundmemt_layout_one,refundmemt_layout;
    private Button true_refundType,false_refundType;
    private EditText refundmemt_comment_one;
    private TextView refundmemt_comment_two;
    private boolean isRefundCheckTrue = true;
    private boolean isRefundCheckFalse = true;
    private String refundType = "00";
    private String refundmemtCommentV = "";
    
    private SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//格式化时间 
	
    private RelativeLayout btn_next;
    
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.order_detail);
		activityList.add(this);
		
		//初始化接钮
		findViewById(R.id.btn_pay).setOnClickListener(this);
		findViewById(R.id.btn_cancel).setOnClickListener(this);
		findViewById(R.id.backBut).setOnClickListener(this);
		findViewById(R.id.btn_refundment).setOnClickListener(this);
		findViewById(R.id.btn_bounce_ticket).setOnClickListener(this);
		findViewById(R.id.btn_abolish_ticket).setOnClickListener(this);
		findViewById(R.id.btn_modifyPassengerIDNo).setOnClickListener(this);
		findViewById(R.id.btn_change_date).setOnClickListener(this);
		//初始化地址参数
		addrUtil = new AddrUtil(this);
		//初始化航空参数
		flyUtil = new FlyUtil(this);

		btn_next =  (RelativeLayout) findViewById(R.id.btn_next);
		
		//初始化字段
//		departureDate = (TextView) findViewById(R.id.departureDate);
//		departureWeek = (TextView) findViewById(R.id.departureWeek);
//		flightNo = (TextView) findViewById(R.id.flightNo); 
		//总订单信息
		order_status = (TextView) findViewById(R.id.order_status);
		order_no = (TextView) findViewById(R.id.order_no);
		order_date = (TextView) findViewById(R.id.order_date);
		totalAmount =  (TextView) findViewById(R.id.totalAmount);
		
		
		passengerName =  (TextView) findViewById(R.id.passengerName); 
		ticketOrderNo =  (TextView) findViewById(R.id.ticketOrderNo); 
		course =  (TextView) findViewById(R.id.course); 
		ticketOrder_date =  (TextView) findViewById(R.id.ticketOrder_date); 
		tripType =  (TextView) findViewById(R.id.tripType); 
		rebate =  (TextView) findViewById(R.id.rebate); 
		ticket_status =  (TextView) findViewById(R.id.ticket_status); 
		
		fromCity = (TextView) findViewById(R.id.fromCity); 
		flight_depart = (TextView) findViewById(R.id.flight_depart); 
		fromtime = (TextView) findViewById(R.id.fromtime);  
		fromaf = (TextView) findViewById(R.id.fromaf);  
		toCity = (TextView) findViewById(R.id.toCity);
		flight_arrive = (TextView) findViewById(R.id.flight_arrive);
		totime = (TextView) findViewById(R.id.totime);
		toaf = (TextView) findViewById(R.id.toaf);
		airc = (TextView) findViewById(R.id.airc);
		baseCabin = (TextView) findViewById(R.id.baseCabin);
		food = (TextView) findViewById(R.id.food);
		stopNo = (TextView) findViewById(R.id.stopNo);
		flight_price_title2 = (TextView) findViewById(R.id.flight_price_title2);
		cabinPrice = (TextView) findViewById(R.id.cabinPrice);
		discount = (TextView) findViewById(R.id.discount);
		price = (TextView) findViewById(R.id.price);
		basePrice = (TextView) findViewById(R.id.basePrice);
		fuelTax = (TextView) findViewById(R.id.fuelTax);
		airc0 = (TextView) findViewById(R.id.airc0);
		others = (TextView) findViewById(R.id.others);
		airc1 = (TextView) findViewById(R.id.airc1);
		airc2 = (TextView) findViewById(R.id.airc2);
		
		itinerary_info_sum_layout = (LinearLayout) findViewById(R.id.itinerary_info_sum_layout);
		ticketOrderNo_layout = (RelativeLayout) findViewById(R.id.ticketOrderNo_layout);
		
		consigneeName = (TextView) findViewById(R.id.consigneeName);
		consigneePhone = (TextView) findViewById(R.id.consigneePhone);
		consigneeAddress = (TextView) findViewById(R.id.consigneeAddress);
		itineraryNo = (TextView) findViewById(R.id.itineraryNo);
		
		passenger_name = (TextView) findViewById(R.id.passenger_name);
		passenger_id_number = (TextView) findViewById(R.id.passenger_id_number);
		contactor_name = (TextView) findViewById(R.id.contactor_name);
		contactor_mobile = (TextView) findViewById(R.id.contactor_mobile);
		sumPrice = (TextView) findViewById(R.id.sumPrice);
		
		//行程单费用,保险花费
		insurancePrice = (TextView) findViewById(R.id.insurancePrice);
		postFee = (TextView) findViewById(R.id.postFee);
		invoiceFee = (TextView) findViewById(R.id.invoiceFee);
		
		renderData();
		
		//退改签
		flightDetailRestrict = (RelativeLayout) findViewById(R.id.flight_detail_restrict);
		flightDetailRestrict.setOnClickListener(this);
		restrict = (TextView) findViewById(R.id.restrict);
		restrictArrow = (ImageView) findViewById(R.id.restrictArrow);
		
		//得到当前日期
        final Calendar calendar = Calendar.getInstance();
        mYear = calendar.get(Calendar.YEAR);
        mMonth = calendar.get(Calendar.MONTH);
        mDay = calendar.get(Calendar.DAY_OF_MONTH);
		
	}
	
	//初始化数据
	private void renderData() {
		//TODO： 再次查找数据
		
		String departureDateValue = "";
		String departureCityValue = "";
		String departureTimeValue = "";
		String arrivalCityValue = "";
		String airLine = "";
		
		flight = new FlightInfo();
		
		if(ORDER_DETAIL.FlightID!=null){
			String[] result = ORDER_DETAIL.FlightID.split(" ");
			airLine = result[2];
			departureCityValue = addrUtil.getCityByCode(result[0]) != null ? addrUtil.getCityByCode(result[0]).getAirName() : "未知城市";
			arrivalCityValue = addrUtil.getCityByCode(result[1]) != null ? addrUtil.getCityByCode(result[1]).getAirName() : "未知城市";
			departureDateValue = result[3];
			
			flight.departure = result[0];
			flight.arrival = result[1];
			flight.airline = airLine.substring(0, 2);
			flight.departureTime = ORDER_DETAIL.DepartureTime;
			flight.cabinFlight = ORDER_DETAIL.Cabin;
			flight.flightNo = airLine;
		}
		System.out.println("flight.departure="+flight.departure);
		System.out.println("flight.arrival="+flight.arrival);
		System.out.println("flight.airline="+flight.airline);
		System.out.println("flight.departureTime="+flight.departureTime);
		System.out.println("flight.cabinFlight="+flight.cabinFlight);
		System.out.println("ORDER_DETAIL.TicketNo="+ORDER_DETAIL.TicketNo);
		
		System.out.println("ORDER_INFO.IBERestrict="+ORDER_DETAIL.IBERestrict);
		
		order_status.setText(flyUtil.orderStatusMap.get(ORDER_DETAIL.Status));
		order_no.setText(ORDER_INFO.OrderNo);
		order_date.setText(ORDER_INFO.CreateTime);
		
		
		passengerName.setText(ORDER_DETAIL.PassengerName);
		
		if(ORDER_DETAIL.TicketNo != null && !ORDER_DETAIL.TicketNo.equals("")){
			ticketOrderNo.setText(ORDER_DETAIL.TicketNo);
		} else {
			ticketOrderNo_layout.setVisibility(View.GONE);
		}
		
		if(ORDER_DETAIL.Course!=null){
			String[] result = ORDER_DETAIL.Course.split(" ");
			airLine = result[2];
			departureCityValue = addrUtil.getCityByCode(result[0]) != null ? addrUtil.getCityByCode(result[0]).getAirName() : "未知城市";
			arrivalCityValue = addrUtil.getCityByCode(result[1]) != null ? addrUtil.getCityByCode(result[1]).getAirName() : "未知城市";
			departureDateValue = result[3];
			course.setText(flyUtil.getName(airLine.substring(0, 2)) + "  " + departureCityValue + "->" + arrivalCityValue);
			ticketOrder_date.setText(departureDateValue);
			airc.setText(airLine);
		}
		
		ticket_status.setText(flyUtil.orderStatusMap.get(ORDER_DETAIL.Status));
		tripType.setText(flyUtil.getTripTypeCode(Integer.valueOf(ORDER_DETAIL.TripType)));
		baseCabin.setText(ORDER_DETAIL.Cabin + " " +  flyUtil.getJClassName(ORDER_DETAIL.Cabin));
		
		
		flight_price_title2.setText("");
		
		cabinPrice.setText("￥" +ORDER_DETAIL.CabinPrice);
		cabinPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG );
		
		price.setText("            现价￥" + String.valueOf(Float.valueOf(ORDER_DETAIL.CabinPrice) - Float.valueOf(ORDER_DETAIL.Rebate)));
		
		rebate.setText("返利￥ " + ORDER_DETAIL.Rebate);
		
		String airportTaxV = (ORDER_DETAIL.AirportTax.equals("") ||  (ORDER_DETAIL.AirportTax == null) ? "0" : ORDER_DETAIL.AirportTax) ;
		String fuelTaxV = (ORDER_DETAIL.FuelTax.equals("") || (ORDER_DETAIL.FuelTax == null) ? "0" : ORDER_DETAIL.FuelTax);
		fuelTax.setText("￥" + airportTaxV + "/￥" + fuelTaxV);
		
//		airc0.setText("同等舱位免费更改。");
//		others.setText("需收取票面价5%的退票费,退票费低于50元按50元收取。");
//		airc1.setText("不得签转。");
		
		passenger_name.setText(ORDER_DETAIL.PassengerName + "  " + flyUtil.getPassengerTypeCode(Integer.valueOf(ORDER_DETAIL.PassengerType)));
		passenger_id_number.setText(flyUtil.getCardTypeLabel(ORDER_DETAIL.PassengerIDType) + "  " + ORDER_DETAIL.PassengerIDNo);
		
		contactor_name.setText(ORDER_DETAIL.ContactName);
		contactor_mobile.setText(ORDER_DETAIL.ContactPhone);
		
		if(ORDER_DETAIL.ItineraryInfo !=null){
			consigneeName.setText(ORDER_DETAIL.ItineraryInfo.getConsigneeName());
			consigneePhone.setText(ORDER_DETAIL.ItineraryInfo.getConsigneePhone());
			consigneeAddress.setText(ORDER_DETAIL.ItineraryInfo.getConsigneeAddress());
			itineraryNo.setText(ORDER_DETAIL.ItineraryInfo.getItineraryOrderNo());
			postFee.setText("￥" + ORDER_DETAIL.PostFee);
			invoiceFee.setText("￥" + ORDER_DETAIL.InvoiceFee);
		} else {
			itinerary_info_sum_layout.setVisibility(View.GONE);
			ORDER_DETAIL.PostFee = "0";
		}
		
		if(!ORDER_DETAIL.Copies.equals("0")){
			insurancePrice.setText(ORDER_DETAIL.Copies + "份 * " + ORDER_DETAIL.InsurancePrice + " = ￥" + ORDER_DETAIL.InsuranceAmount);
		} else {
			insurancePrice.setText("￥0元");
			ORDER_DETAIL.InsuranceAmount = "0";
		}
		
		float sumPriceV = Float.valueOf(ORDER_DETAIL.CabinPrice) - Float.valueOf(ORDER_DETAIL.Rebate) + Float.valueOf(airportTaxV) + Float.valueOf(fuelTaxV) + Float.valueOf(ORDER_DETAIL.PostFee) + Float.valueOf(ORDER_DETAIL.InsuranceAmount);
		
		sumPrice.setText("￥" + String.valueOf(sumPriceV));
		totalAmount.setText("￥" + String.valueOf(sumPriceV));
		
		//根据状态显示可操作的按键
		String flyOrderStatus = ORDER_DETAIL.Status;//ORDER_DETAIL.Status;TODO要修改
		orderStatus(flyOrderStatus);
	}
	
	private void orderStatus(String flyOrderStatus){
		//订单状态转成int型数据
		int status = 0;
		try {
			status = Integer.parseInt(flyOrderStatus);
		} catch(Exception e) {
			status = 100;
		}
		
		switch (status){
			case 0:
				//0	待订座，待支付
				//按钮：支付出票 取消订单
				//注：支付出票需在订单生成半小时内
//				String nowDate = DateUtil.getDateTime();
//				try {
//					long result=(dateFormat.parse(nowDate).getTime()-dateFormat.parse(ORDER_INFO.CreateTime).getTime())/3600000;
//					
//					System.out.println("result="+result);
//					if(result<0.5){
//						findViewById(R.id.btn_pay).setVisibility(View.VISIBLE);
//					}
//				} catch (ParseException e) {
//					e.printStackTrace();
//				}
				findViewById(R.id.btn_pay).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_cancel).setVisibility(View.VISIBLE);
				break;
			case 100:
				//无效订单
				btn_next.setVisibility(View.GONE);
				break;
			case 200:
				//200	已订座，待支付
				//按钮：支付出票 取消订单
				//注：支付出票需在订单生成半小时内
//				String nowDate2 = DateUtil.getDateTime();
//				try {
//					long result=(dateFormat.parse(nowDate2).getTime()-dateFormat.parse(ORDER_INFO.CreateTime).getTime())/3600000;
//					
//					System.out.println("result="+result);
//					if(result<0.5){
//						findViewById(R.id.btn_pay).setVisibility(View.VISIBLE);
//					}
//				} catch (ParseException e) {
//					e.printStackTrace();
//				}
				findViewById(R.id.btn_pay).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_cancel).setVisibility(View.VISIBLE);
				break;
			case 201:
				//201	已订座，待支付
				//按钮：支付出票 取消订单
				//注：取消订单操作会取消总订单内所有的机票预订
//				String nowDate3 = DateUtil.getDateTime();
//				try {
//					long result=(dateFormat.parse(nowDate3).getTime()-dateFormat.parse(ORDER_INFO.CreateTime).getTime())/3600000;
//					
//					System.out.println("result="+result);
//					if(result<0.5){
//						findViewById(R.id.btn_pay).setVisibility(View.VISIBLE);
//					}
//				} catch (ParseException e) {
//					e.printStackTrace();
//				}
				findViewById(R.id.btn_pay).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_cancel).setVisibility(View.VISIBLE);
				break;
			case 202:
				//202	已订座，支付失败
				//按钮：支付出票 取消订单
				//注：取消订单操作会取消总订单内所有的机票预订
				String nowDate4 = DateUtil.getDateTime();
				try {
					long result=(dateFormat.parse(nowDate4).getTime()-dateFormat.parse(ORDER_INFO.CreateTime).getTime())/3600000;
					
					System.out.println("result="+result);
					if(result<0.5){
						findViewById(R.id.btn_pay).setVisibility(View.VISIBLE);
					}
				} catch (ParseException e) {
					e.printStackTrace();
				}
				findViewById(R.id.btn_cancel).setVisibility(View.VISIBLE);
				break;
			case 203:
				//203	已订座，支付成功，待出票
				//按钮：获取票号
//				findViewById(R.id.btn_get_ticket).setVisibility(View.VISIBLE);
				break;
			case 204:
				//204	出票失败
				//按钮：申请全额退款
				findViewById(R.id.btn_refundment).setVisibility(View.VISIBLE);
				break;
			case 205:
				//205	出票完成，未获取到票号
				//按钮：获取票号
//				findViewById(R.id.btn_get_ticket).setVisibility(View.VISIBLE);
				break;
			case 206:
				//206	已出票
				//按钮：退票，废票，升舱，改期，修改证件
				findViewById(R.id.btn_bounce_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_abolish_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_change_date).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_modifyPassengerIDNo).setVisibility(View.VISIBLE);
				break;
			case 207:
				//207	已出票，未打印行程单	
				//按钮：索取行程单
				//注： 航班起飞一星期内可打印行程单
				break;
			case 208:
				//208	已出票，已打印行程单
				//按钮：退票，废票，升舱，改期，修改证件
				findViewById(R.id.btn_bounce_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_abolish_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_change_date).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_modifyPassengerIDNo).setVisibility(View.VISIBLE);
				break;
			case 301:
				//301	申请退票失败	
				//按钮：废票、退票、改期、修改证件号
				findViewById(R.id.btn_abolish_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_bounce_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_change_date).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_modifyPassengerIDNo).setVisibility(View.VISIBLE);
				break;
				
			case 401:
				//401	申请废票失败	
				//按钮：废票、退票、改期、修改证件号
				findViewById(R.id.btn_abolish_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_bounce_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_change_date).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_modifyPassengerIDNo).setVisibility(View.VISIBLE);
				break;
				
			case 701:
				//701	申请改期失败	
				//按钮：废票、退票、改期、修改证件号
				findViewById(R.id.btn_abolish_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_bounce_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_change_date).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_modifyPassengerIDNo).setVisibility(View.VISIBLE);
				break;
				
			case 703:
				//703	改期失败
				//按钮：废票、退票、改期、修改证件号
				findViewById(R.id.btn_abolish_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_bounce_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_change_date).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_modifyPassengerIDNo).setVisibility(View.VISIBLE);
				break;
			case 704:
				//704	改期成功
				//按钮：废票、退票、改期、修改证件号
				findViewById(R.id.btn_abolish_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_bounce_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_change_date).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_modifyPassengerIDNo).setVisibility(View.VISIBLE);
				break;
			case 503:
				//503	修改乘机人证件号成功	
				//按钮：废票、退票、改期、修改证件号
				findViewById(R.id.btn_abolish_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_bounce_ticket).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_change_date).setVisibility(View.VISIBLE);
				findViewById(R.id.btn_modifyPassengerIDNo).setVisibility(View.VISIBLE);
				break;
			default:
				btn_next.setVisibility(View.GONE);
		}
	}
	
	//申请全额退款
	private void refundment(){
		WindowManager manager = getWindowManager();   
	    Display display = manager.getDefaultDisplay();   
	    int width = display.getWidth();   
	    int height = display.getHeight();   
	       
	    LayoutInflater inflater = getLayoutInflater();   
	    View view = inflater.inflate(R.layout.order_refundment, null);   
	       
	    refundmemt_comment = (EditText)view.findViewById(R.id.refundmemt_comment);   
	       
	    //弹出提示框
	    refundmemt_comment = (EditText)view.findViewById(R.id.refundmemt_comment);
	    refundmemt_comment.setGravity(Gravity.LEFT);
//	    refundmemt_comment.setKeyListener(DialerKeyListener.getInstance());
        refundmemtDialog = new AlertDialog.Builder(
        		OrderDetail.this).setTitle("申请全额退款")
				.setPositiveButton("申请",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								String refundmemtComment = refundmemt_comment.getText().toString();
								System.out.println("refundmemtComment="+refundmemtComment);
								if (!refundmemtComment.equals("")) {
									//提交申请
									//显示申请成功
									progressDialog = ProgressDialog.show(OrderDetail.this, "请稍等...", "正在申请全额退款...",true);
									final Thread thread1 = new Thread() {
										public void run() {
											OrderInfoResult orderResult = WebAccessor.applyForReturnAmount(OrderDetail.this, ORDER_DETAIL.TicketOrderNo);
											if (progressDialog.isShowing()) {
												if (orderResult== null) {
													Message msg = new Message();
													msg.what = FAIL;
													msg.obj = "申请全额退款操作失败";
													myHandler.sendMessage(msg);
												}else if(!"0".equals(orderResult.Ret_Code)){
													Message msg = new Message();
													msg.what = FAIL;
													msg.obj = orderResult.Ret_Msg;
													myHandler.sendMessage(msg);
												}else{
													Message msg = new Message();
													msg.what = RETURN_AMOUNT_SUCCESS;
													myHandler.sendMessage(msg);
												}
												progressDialog.dismiss();
											}
										}
									};
									progressDialog.setCancelable(true);
									thread1.start();
								} else {
									//显示保存失败
									toast = Toast.makeText(OrderDetail.this, "申请原因不能为空！", Toast.LENGTH_LONG);
									toast.setGravity(Gravity.CENTER, 0, 0);
									toast.show();
								}
							}
						}).setNegativeButton("取消",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								refundmemtDialog.dismiss();
								refundmemtDialog.cancel();
								refundmemtDialog = null;
							}
						}).create();
        refundmemtDialog.setView(view);
        refundmemtDialog.getWindow().setLayout(width/2, height/4);   
	    refundmemtDialog.show();
	}
	
	/**
	 * 退票接口
	 * @param c
	 * @param orderNo 一站式订单号
	 * @param refundType退订类型	00自愿退票 01非自愿退票
	 * @param applyReason申请退订理由
	 * @param contact退订联系人
	 * @param contactPhone退订联系人电话
	 * @return
	 */
	private void applyForRefund(){
		WindowManager manager = getWindowManager();   
	    Display display = manager.getDefaultDisplay();   
	    int width = display.getWidth();   
	    int height = display.getHeight();   
	       
	    LayoutInflater inflater = getLayoutInflater();   
	    View view = inflater.inflate(R.layout.order_apply_refund, null);   
	       

	    refundmemt_layout_one = (LinearLayout)view.findViewById(R.id.refundmemt_layout_one);
	    refundmemt_layout = (LinearLayout)view.findViewById(R.id.refundmemt_layout);
	    refundmemt_layout_one.setOnClickListener(OrderDetail.this);
	    
	    true_refundType = (Button)view.findViewById(R.id.true_refundType);
	    false_refundType = (Button)view.findViewById(R.id.false_refundType);
	    true_refundType.setOnClickListener(OrderDetail.this);
	    false_refundType.setOnClickListener(OrderDetail.this);
	    
	    //弹出提示框
	    refundmemt_comment_one = (EditText)view.findViewById(R.id.refundmemt_comment_one);
	    refundmemt_comment_two = (TextView)view.findViewById(R.id.refundmemt_comment_two);
	    
	    refundmemt_comment_one.setGravity(Gravity.LEFT);
//	    refundmemt_comment.setKeyListener(DialerKeyListener.getInstance());
        refundmemtDialog = new AlertDialog.Builder(
        		OrderDetail.this).setTitle("申请退票")
				.setPositiveButton("申请",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								final String refundmemtCommentOne = String.valueOf(refundmemt_comment_one.getText());
								final String refundmemtCommentTwo = String.valueOf(refundmemt_comment_two.getText());
								if(refundmemtCommentOne!=null && !"".equals(refundmemtCommentOne)){
									refundmemtCommentV = refundmemtCommentOne;
								}
								if(refundmemtCommentTwo!=null && !"".equals(refundmemtCommentTwo)){
									refundmemtCommentV = refundmemtCommentTwo;
								}
								System.out.println("refundmemtCommentV="+refundmemtCommentV);
								if (!refundmemtCommentV.equals("")) {
									//提交申请
									progressDialog = ProgressDialog.show(OrderDetail.this, "请稍等...", "正在申请退票...",true);
									final Thread thread1 = new Thread() {
										public void run() {
											OrderInfoResult orderResult = WebAccessor.applyForRefund(OrderDetail.this, ORDER_DETAIL.TicketOrderNo, refundType, refundmemtCommentV.trim(), ORDER_DETAIL.ContactName, ORDER_DETAIL.ContactPhone);
											if (progressDialog.isShowing()) {
												if (orderResult== null) {
													Message msg = new Message();
													msg.what = FAIL;
													msg.obj = "申请退票操作失败";
													myHandler.sendMessage(msg);
												}else if(!"0".equals(orderResult.Ret_Code)){
													Message msg = new Message();
													msg.what = FAIL;
													msg.obj = orderResult.Ret_Msg;
													myHandler.sendMessage(msg);
												}else{
													Message msg = new Message();
													msg.what = APPLY_FOR_REFUND_SUCCESS;
													myHandler.sendMessage(msg);
												}
												progressDialog.dismiss();
											}
										}
									};
									progressDialog.setCancelable(true);
									thread1.start();
									
								} else {
									//显示保存失败
									toast = Toast.makeText(OrderDetail.this, "申请原因不能为空！", Toast.LENGTH_LONG);
									toast.setGravity(Gravity.CENTER, 0, 0);
									toast.show();
								}
							}
						}).setNegativeButton("取消",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								refundmemtDialog.dismiss();
								refundmemtDialog.cancel();
								refundmemtDialog = null;
							}
						}).create();
        refundmemtDialog.setView(view);
        refundmemtDialog.getWindow().setLayout(width/2, height/4);   
	    refundmemtDialog.show();
	}
	
	
	/**
	 * 修改乘客证件号码
	 * @return
	 */
	private void modifyPassengerIDNo(){
		WindowManager manager = getWindowManager();   
	    Display display = manager.getDefaultDisplay();   
	    int width = display.getWidth();   
	    int height = display.getHeight();   
	       
	    LayoutInflater inflater = getLayoutInflater();   
	    View view = inflater.inflate(R.layout.order_modify_passenger_no, null);   
	       
	    TextView oldPassengerIDNo = (TextView)view.findViewById(R.id.old_PassengerIDNo_title);
	    oldPassengerIDNo.setText("原证件号：" + FlyUtil.getCardLabel(Integer.valueOf(ORDER_DETAIL.PassengerIDType)) + " " + ORDER_DETAIL.PassengerIDNo);
	    
	    new_PassengerIDNo = (EditText)view.findViewById(R.id.new_PassengerIDNo);
	    new_PassengerIDNo.setGravity(Gravity.LEFT);
	    modifyPassengerIDNoDialog = new AlertDialog.Builder(
        		OrderDetail.this).setTitle("修改乘客证件号码")
				.setPositiveButton("修改",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								final String newPassengerIDNo = new_PassengerIDNo.getText().toString();
								if (!newPassengerIDNo.equals("")) {
									//提交申请
									progressDialog = ProgressDialog.show(OrderDetail.this, "请稍等...", "正在申请修改乘客证件号码...",true);
									final Thread thread1 = new Thread() {
										public void run() {
											OrderInfoResult orderResult = WebAccessor.modifyPassengerIDNo(OrderDetail.this, ORDER_DETAIL.TicketOrderNo, ORDER_DETAIL.PassengerName, newPassengerIDNo.trim());
											if (progressDialog.isShowing()) {
												if (orderResult== null) {
													Message msg = new Message();
													msg.what = FAIL;
													msg.obj = "申请修改乘客证件号码操作失败";
													myHandler.sendMessage(msg);
												}else if(!"0".equals(orderResult.Ret_Code)){
													Message msg = new Message();
													msg.what = FAIL;
													msg.obj = orderResult.Ret_Msg;
													myHandler.sendMessage(msg);
												}else{
													Message msg = new Message();
													msg.what = MODIFY_NO_SUCCESS;
													myHandler.sendMessage(msg);
												}
												progressDialog.dismiss();
											}
										}
									};
									progressDialog.setCancelable(true);
									thread1.start();
									
								} else {
									//显示保存失败
									toast = Toast.makeText(OrderDetail.this, "证件号码不能为空！", Toast.LENGTH_LONG);
									toast.setGravity(Gravity.CENTER, 0, 0);
									toast.show();
								}
							}
						}).setNegativeButton("取消",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								modifyPassengerIDNoDialog.dismiss();
								modifyPassengerIDNoDialog.cancel();
								modifyPassengerIDNoDialog = null;
							}
						}).create();
	    modifyPassengerIDNoDialog.setView(view);
	    modifyPassengerIDNoDialog.getWindow().setLayout(width/2, height/4);   
	    modifyPassengerIDNoDialog.show();
	}
	

	/**
	 * 机票申请改期
	 * @return
	 */
	private void changeDateApply(){
		WindowManager manager = getWindowManager();   
	    Display display = manager.getDefaultDisplay();   
	    int width = display.getWidth();   
	    int height = display.getHeight();   
	       
	    LayoutInflater inflater = getLayoutInflater();   
	    View view = inflater.inflate(R.layout.order_change_date_apply, null);   
	       
	    
	    if(ORDER_DETAIL.Course!=null){
			String[] result = ORDER_DETAIL.Course.split(" ");
			String airLine = result[2];
			TextView oldAirFlightNoTitle = (TextView)view.findViewById(R.id.old_AirFlightNo_title);
			oldAirFlightNoTitle.setText("原航班号：" + airLine + " " + flyUtil.getName(airLine.substring(0, 2)));
		}
	    newAirFlightNo = (EditText)view.findViewById(R.id.newAirFlightNo);
	    newAirFlightNo.setGravity(Gravity.LEFT);
	    applyReason = (EditText)view.findViewById(R.id.applyReason);
	    applyReason.setGravity(Gravity.LEFT);
	    
	    //改期
	    newDate = (TextView)view.findViewById(R.id.newDate);
		new_date_layout = (LinearLayout) view.findViewById(R.id.new_date_layout);
		new_date_layout.setOnClickListener(OrderDetail.this);
		
	    changeDateApplyDialog = new AlertDialog.Builder(
        		OrderDetail.this).setTitle("机票申请改期")
				.setPositiveButton("申请",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								final String newAirFlightNoText = newAirFlightNo.getText().toString();
								final String applyReasonText = applyReason.getText().toString();
								System.out.println("newDateStr="+newDateStr);
								if (!newAirFlightNoText.equals("") && !applyReasonText.equals("") && !newDateStr.equals("")) {
									//提交申请
									progressDialog = ProgressDialog.show(OrderDetail.this, "请稍等...", "正在申请机票改期...",true);
									final Thread thread1 = new Thread() {
										public void run() {
											ChangeDateData changeDateData = new ChangeDateData();
											changeDateData.airFlightNo = flight.flightNo;
											changeDateData.airTicketNo = ORDER_DETAIL.TicketNo;
											changeDateData.pagName = ORDER_DETAIL.PassengerName;
											changeDateData.newAirFlightNo = newAirFlightNoText.trim();
											changeDateData.ticketChangeDate = newDateStr;
											OrderInfoResult orderResult = WebAccessor.changeDateApply(OrderDetail.this, ORDER_DETAIL.TicketOrderNo, changeDateData, applyReasonText.trim(),ORDER_DETAIL.ContactName,ORDER_DETAIL.ContactPhone);
											if (progressDialog.isShowing()) {
												if (orderResult== null) {
													Message msg = new Message();
													msg.what = FAIL;
													msg.obj = "机票申请改期操作失败";
													myHandler.sendMessage(msg);
												}else if(!"0".equals(orderResult.Ret_Code)){
													Message msg = new Message();
													msg.what = FAIL;
													msg.obj = orderResult.Ret_Msg;
													myHandler.sendMessage(msg);
												}else{
													Message msg = new Message();
													msg.what = CHANGEDATE_SUCCESS;
													myHandler.sendMessage(msg);
												}
												progressDialog.dismiss();
											}
										}
									};
									progressDialog.setCancelable(true);
									thread1.start();
									
								} else {
									//显示保存失败
									toast = Toast.makeText(OrderDetail.this, "请输入完整信息！", Toast.LENGTH_LONG);
									toast.setGravity(Gravity.CENTER, 0, 0);
									toast.show();
								}
							}
						}).setNegativeButton("取消",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								changeDateApplyDialog.dismiss();
								changeDateApplyDialog.cancel();
								changeDateApplyDialog = null;
							}
						}).create();
	    changeDateApplyDialog.setView(view);
	    changeDateApplyDialog.getWindow().setLayout(width/2, height/4);   
	    changeDateApplyDialog.show();
	}
	
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_pay: {
			//付款
			String[] FlightOrderNOArray = new String[ORDER_INFO.TicketOrders.size()];
			for (int i = 0; i < FlightOrderNOArray.length; i ++) {
				FlightOrderNOArray[i] = ORDER_INFO.TicketOrders.get(i).OrderNo;
			}
			
			TotalOrderInfoResult orderResult = new TotalOrderInfoResult();
			orderResult.OrderNO = ORDER_INFO.OrderNo;
			orderResult.FlightOrderNO = FlightOrderNOArray;
			
			//跳转到信用卡支付页面
			Intent intent = new Intent();
			intent.setClass(OrderDetail.this, CreditCard.class);
			CreditCard.totalOrderInfoResult = orderResult;
			CreditCard.sumPriceFormat = ORDER_INFO.TotalAmount;
			CreditCard.isNowPay = true;
			CreditCard.flight = flight;
			startActivity(intent);
			break;
		}
		case R.id.btn_cancel: {
			//取消订单
			AlertDialog.Builder builder = new AlertDialog.Builder(this);    
			builder.setTitle("取消订单");    
			builder.setMessage("您正在进行取消订单的操作,请确认!");  
			builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {    
			public void onClick(DialogInterface dialog, int which) {   
				progressDialog = ProgressDialog.show(OrderDetail.this, "请稍等...", "正在取消订单中...",true);
				final Thread thread1 = new Thread() {
					public void run() {
						OrderInfoResult orderResult = WebAccessor.applyForCountermand(OrderDetail.this, ORDER_DETAIL.TicketOrderNo);
						if (progressDialog.isShowing()) {
							if (orderResult== null) {
								Message msg = new Message();
								msg.what = FAIL;
								msg.obj = "取消订单操作失败";
								myHandler.sendMessage(msg);
							}else if(!"0".equals(orderResult.Ret_Code)){
								Message msg = new Message();
								msg.what = FAIL;
								msg.obj = orderResult.Ret_Msg;
								myHandler.sendMessage(msg);
							}else{
								Message msg = new Message();
								msg.what = CANCEL_SUCCESS;
								myHandler.sendMessage(msg);
								//更新页面状态
	//							ticket_status.setText(flyUtil.orderStatusMap.get(ORDER_DETAIL.Status));
							}
							progressDialog.dismiss();
						}
					}
				};
				progressDialog.setCancelable(true);
				thread1.start();
			}
			});    
			   
			builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {    
			public void onClick(DialogInterface dialog, int which) {    
			dialog.cancel();    
			}    
			});    
			   
			AlertDialog ad = builder.create();    
			ad.show();  
			break;
		}
		case R.id.backBut: {
			Intent intent = new Intent(OrderDetail.this, OrderList.class);
			OrderList.UPDATE_INDICATOR = true;
			startActivity(intent);
			
			break;
		}
		case R.id.btn_refundment: {
			//申请全额退款
			refundment();
			break;
		}
		case R.id.btn_bounce_ticket:{
			//退票
			applyForRefund();
			break;
		}
		case R.id.btn_abolish_ticket:{
			//申请废票
			AlertDialog.Builder builder = new AlertDialog.Builder(this);    
			builder.setTitle("申请废票");    
			builder.setMessage("当天支付的订单在航班起飞前2小时才可提交当天作废机票，具体按照中国民航票规执行。操作过程中产生废票手续费10元！");    
			builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {    
			public void onClick(DialogInterface dialog, int which) {   
				progressDialog = ProgressDialog.show(OrderDetail.this, "请稍等...", "正在申请废票中...",true);
				final Thread thread1 = new Thread() {
					public void run() {
						OrderInfoResult orderResult = WebAccessor.applyForVoidTicket(OrderDetail.this, ORDER_DETAIL.TicketOrderNo,ORDER_DETAIL.PNR,ORDER_DETAIL.TicketNo);
						System.out.println("orderResult="+orderResult);
						if (progressDialog.isShowing()) {
							if (orderResult== null) {
								Message msg = new Message();
								msg.what = FAIL;
								msg.obj = "申请废票操作失败";
								myHandler.sendMessage(msg);
							}else if(!"0".equals(orderResult.Ret_Code)){
								Message msg = new Message();
								msg.what = FAIL;
								msg.obj = orderResult.Ret_Msg;
								myHandler.sendMessage(msg);
							}else{
								Message msg = new Message();
								msg.what = ABOLISH_SUCCESS;
								myHandler.sendMessage(msg);
							}
							progressDialog.dismiss();
						}
					}
				};
				progressDialog.setCancelable(true);
				thread1.start();
			}
			});    
			   
			builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {    
			public void onClick(DialogInterface dialog, int which) {    
			dialog.cancel();    
			}    
			});    
			   
			AlertDialog ad = builder.create();    
			ad.show();  
			
			break;
		}
		case R.id.btn_modifyPassengerIDNo:
			//修改乘客证件号码
			modifyPassengerIDNo();
			break;
		case R.id.btn_change_date:
			//机票申请改期
			changeDateApply();
			break;	
			
		case R.id.flight_detail_restrict:
			if(isOpenRestrict){
				String detailRestrict = ((FlyApplication)getApplication()).getPolicyRule();
				if(detailRestrict == null){
					getFlightRestrict();
				}
				isOpenRestrict = false;
			} else {
				restrict.setText("点击查看详细...");
				restrictArrow.setVisibility(View.GONE);
				isOpenRestrict = true;
			}
			
			break;
			
		case R.id.new_date_layout:
			showDialog(TIME_DIALOG_ID);
			showDialog(DATE_DIALOG_ID);
			break;
			
		//退订类型
		case R.id.true_refundType:
			if(isRefundCheckTrue){
				false_refundType.setBackgroundResource(R.drawable.button_unchecked);
				true_refundType.setBackgroundResource(R.drawable.button_checked);
				isRefundCheckTrue = false;
				refundType = "00";
//				refundmemt_layout.setVisibility(View.VISIBLE);
//				refundmemt_layout_one.setVisibility(View.GONE);
			}else{
				false_refundType.setBackgroundResource(R.drawable.button_checked);
				true_refundType.setBackgroundResource(R.drawable.button_unchecked);
				isRefundCheckTrue = true;
				refundType = "01";
//				refundmemt_layout.setVisibility(View.GONE);
				refundmemt_layout_one.setVisibility(View.VISIBLE);
			}
			break;
		case R.id.false_refundType:
			if(isRefundCheckFalse){
				false_refundType.setBackgroundResource(R.drawable.button_checked);
				true_refundType.setBackgroundResource(R.drawable.button_unchecked);
				isRefundCheckFalse = false;
				refundType = "01";
//				refundmemt_layout.setVisibility(View.GONE);
//				refundmemt_layout_one.setVisibility(View.VISIBLE);
			}else{
				false_refundType.setBackgroundResource(R.drawable.button_unchecked);
				true_refundType.setBackgroundResource(R.drawable.button_checked);
				isRefundCheckFalse = true;
				refundType = "00";
//				refundmemt_layout.setVisibility(View.VISIBLE);
//				refundmemt_layout_one.setVisibility(View.GONE);
			}
			break;
		case R.id.refundmemt_layout_one:
			showDialog(REFUNDTYPE_DIALOG_LIST);
			break;
		}
		
		
	}

	//处理
	Handler myHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case SUCCESS:
				toast = Toast.makeText(OrderDetail.this, "操作成功", Toast.LENGTH_LONG);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();
				break;
			case FAIL:
				BaseHelper.showDialog(OrderDetail.this, "提示", (String)msg.obj,
						R.drawable.infoicon);
				break;
			case CANCEL_SUCCESS:
				toast = Toast.makeText(OrderDetail.this, "取消订单成功", Toast.LENGTH_LONG);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();
				//更新页面状态
				Intent intent1 = new Intent(OrderDetail.this, OrderList.class);
				OrderList.orderist.clear();
				SearchOrder searchOrder1 = new SearchOrder();
				searchOrder1.OrderNo = ORDER_DETAIL.TicketOrderNo;
				OrderList.searchOrder = searchOrder1;
    			startActivity(intent1);
				break;
			case ABOLISH_SUCCESS:
				toast = Toast.makeText(OrderDetail.this, "申请废票成功", Toast.LENGTH_LONG);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();
				
				
				Intent intent2 = new Intent(OrderDetail.this, OrderList.class);
				OrderList.orderist.clear();
				SearchOrder searchOrder2 = new SearchOrder();
				searchOrder2.OrderNo = ORDER_DETAIL.TicketOrderNo;
				OrderList.searchOrder = searchOrder2;
    			startActivity(intent2);
    			
				break;
			case RETURN_AMOUNT_SUCCESS:
				toast = Toast.makeText(OrderDetail.this, "申请退款成功", Toast.LENGTH_LONG);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();
				//更新页面状态
				Intent intent3 = new Intent(OrderDetail.this, OrderList.class);
				OrderList.orderist.clear();
				SearchOrder searchOrder3 = new SearchOrder();
				searchOrder3.OrderNo = ORDER_DETAIL.TicketOrderNo;
				OrderList.searchOrder = searchOrder3;
    			startActivity(intent3);
				break;
			case APPLY_FOR_REFUND_SUCCESS:
				toast = Toast.makeText(OrderDetail.this, "申请退票成功", Toast.LENGTH_LONG);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();
				//更新页面状态
				Intent intent4 = new Intent(OrderDetail.this, OrderList.class);
				OrderList.orderist.clear();
				SearchOrder searchOrder4 = new SearchOrder();
				searchOrder4.OrderNo = ORDER_DETAIL.TicketOrderNo;
				OrderList.searchOrder = searchOrder4;
    			startActivity(intent4);
				break;				
			case MODIFY_NO_SUCCESS:
				toast = Toast.makeText(OrderDetail.this, "申请修改乘客证件号码成功", Toast.LENGTH_LONG);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();
				//更新页面状态
				Intent intent5 = new Intent(OrderDetail.this, OrderList.class);
				OrderList.orderist.clear();
				SearchOrder searchOrder5 = new SearchOrder();
				searchOrder5.OrderNo = ORDER_DETAIL.TicketOrderNo;
				OrderList.searchOrder = searchOrder5;
    			startActivity(intent5);
				break;	
			case CHANGEDATE_SUCCESS:
				toast = Toast.makeText(OrderDetail.this, "申请机票申请改期成功", Toast.LENGTH_LONG);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();
				//更新页面状态
				Intent intent6 = new Intent(OrderDetail.this, OrderList.class);
				OrderList.orderist.clear();
				SearchOrder searchOrder6 = new SearchOrder();
				searchOrder6.OrderNo = ORDER_DETAIL.TicketOrderNo;
				OrderList.searchOrder = searchOrder6;
    			startActivity(intent6);
				break;					
				
			}
			super.handleMessage(msg);
		}
	};
	
	
	private void getFlightRestrict() {
		progressDialog = ProgressDialog.show(this, "请稍等...", "查询退改签明细...",true);
		final Thread thread = new Thread() {
			public void run() {
				flightRestrict =  WebAccessor.getFlightRestrict(OrderDetail.this,flight);
				if (progressDialog.isShowing()) {
					if (flightRestrict!= null) {
						Message msg = new Message();
						msg.what = SUCCESS;
						restrictHandler.sendMessage(msg);
					} else {
						Message msg = new Message();
						msg.what = SEARCH_ERROR;
						msg.obj = "无法查询到退改签明细";
						restrictHandler.sendMessage(msg);
					}
					progressDialog.dismiss();
				}
			}
		};
		progressDialog.setCancelable(true);
		thread.start();
	}
	
	public Handler restrictHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case SEARCH_ERROR:
				Toast.makeText(OrderDetail.this, (String)msg.obj, Toast.LENGTH_LONG).show();
				break;
			case SUCCESS:
				restrictValue = flightRestrict.airc0;
				//退订票规则
				System.out.println("restrictValue="+restrictValue);
				restrict.setText(restrictValue);
				restrictArrow.setVisibility(View.GONE);
				break;
			}
		}
	};
	
	@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		    case DATE_DIALOG_ID:
		    	return new DatePickerDialog(this, dsl, mYear, mMonth, mDay);
		    case TIME_DIALOG_ID:
		    	return new TimePickerDialog(this, ts1,mHour,mMinute,true);
		    case REFUNDTYPE_DIALOG_LIST:
		    	return new AlertDialog.Builder(OrderDetail.this)
                .setIcon(R.drawable.ic_menu_more)
                .setTitle("请选择")
                .setSingleChoiceItems(R.array.refund_type, 0, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    	String[] arrs = getResources().getStringArray(R.array.refund_type);
                    	refundmemt_comment_two.setText(arrs[whichButton]);
                    	dialog.dismiss();
                        /* User clicked on a radio button do some stuff */
                    }
                })
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                })
               .create();
		default:
			return null;
		}
	}
	
	
    //准备日期设置监听器
    private OnDateSetListener dsl = new DatePickerDialog.OnDateSetListener(){

		public void onDateSet(DatePicker view, int year, int monthOfYear,
				int dayOfMonth) {
			mYear =year;
			mMonth= monthOfYear;
			mDay= dayOfMonth;
			newDateStr = mYear+"-"+DateUtil.pad(mMonth+1)+"-"+DateUtil.pad(mDay);
			newDate.setText(newDateStr);
		}
    };
    
    private OnTimeSetListener ts1 = new OnTimeSetListener(){

		public void onTimeSet(TimePicker arg0, int hour, int minute) {
			// TODO Auto-generated method stub
			mHour = hour;
			mMinute = minute;
			newDateStr = mYear+"-"+DateUtil.pad(mMonth+1)+"-"+DateUtil.pad(mDay) + " " + DateUtil.pad(mHour) + ":" + DateUtil.pad(mMinute);
			System.out.println("format newDateStr = " + newDateStr);
			newDate.setText(newDateStr);
		}
    	
    };

	public void onResume() {     
		super.onResume();     
		MobclickAgent.onResume(this); 
	}  
	
	public void onPause() {     
		super.onPause();     
		MobclickAgent.onPause(this); 
	}  
}


